<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>

<html>
  <head>
    <base target="_self" />
    <title>新增联系人</title>
    
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="新增,联系人" />
	<meta http-equiv="description" content="addContact" />
	<style type="text/css">
	</style>
  </head>
  
  <body>
  
    <center>
    	<s:form name="frm" id="frm" method="post" action="" namespace="">
    		<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
    			<jsp:param name="menuLink" value="[{'name':'公共管理'},{'name':'通讯录管理'},{'name':'新增联系人'}]"/>
    			<jsp:param name="width" value="70%"/>
    		</jsp:include>
    		<s:hidden name="iskg" id="iskg"></s:hidden>
    		<s:hidden name="kindergartenId" id="kindergartenId"></s:hidden>
    		
    		<table width="100%" cellspacing="1" cellpadding="3" bgcolor="#CCCCCC">
    			<tr bgcolor="#FFFFFF">
    				<td width="25%" align="right" class="label">
    					姓名：
    					<br/>
    					<font color="red">(20字以内)</font>
    				</td>
    				<td width="75%" align="left" colspan="3">
    					<s:textfield name="ct.name" id="name" cssStyle="width:100%" maxlength="20"></s:textfield>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td width="25%" align="right" class="label">
    					电话：
    					<br/>
    					<font color="red">(多个号码请以分号(;)隔开)</font>
    				</td>
    				<td width="75%" align="left" colspan="3">
    					<s:textfield name="ct.phone" id="phone" cssStyle="width:100%" maxlength="50"></s:textfield>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td width="25%" align="right" class="label">
    					地址：
    					<br/>
    					<font color="red">(50字以内)</font>
    				</td>
    				<td width="75%" align="left" colspan="3">
    					<s:textfield name="ct.address" id="address" cssStyle="width:100%" maxlength="50"></s:textfield>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td width="25%" align="right" class="label">
    					邮箱：
    					<br/>
    					<font color="red">(多个邮箱请以分号(;)隔开)</font>
    				</td>
    				<td width="75%" align="left" colspan="3">
    					<s:textfield name="ct.email" id="email" cssStyle="width:100%" maxlength="100"></s:textfield>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td width="25%" align="right" class="label">
    					主页：
    					<br/>
    					<font color="red"></font>
    				</td>
    				<td width="75%" align="left" colspan="3">
    					<s:textfield name="ct.url" id="url" cssStyle="width:100%" maxlength="100"></s:textfield>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					类型：
    				</td>
    				<td align="left" colspan="3">
    					<s:select name="ct.type" id="type" list='typeList' listKey="value" listValue="label" cssStyle="width:100px" headerKey="" headerValue="--请选择--"></s:select>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td align="right" class="label">
    					描述：
    					<br/>
    					<font color="red">(100字以内)</font>
    				</td>
    				<td align="left" colspan="3">
    					<s:textarea name="ct.description" id="description" cssStyle="width:100%; height:80px"></s:textarea>
    				</td>
    			</tr>
    		</table>
    		
    		<table width="100%" cellspacing="0">
    			<tr>
    				<td align="center" valign="bottom" height="30">
    					<input type="button" value="新增" class="btn" onclick="addContact();" />
    				</td>
    			</tr>
    		</table>
    		
    		
    	</s:form>
    </center>
    <script type="text/javascript">
    	String.prototype.Trim = function() {
	var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/);
	return (m == null) ? "" : m[1];
}

String.prototype.isMobile = function() {
	return (/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/.test(this.Trim()));
}

String.prototype.isTel = function() {
	// "兼容格式: 国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)"
	// return
	// (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
	return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
}
function addContact() {
	var name = $('#name');
	var phone = $('#phone');
	var email = $('#email');
	var description = $('#description');
	
	var isemail=(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);
	//var isemail = new RegExp(/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/g);
	//var isemail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
	//var isphone=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/;
	
	if(!isNotNull(name.val()))
	{
		showMsg('姓名不能为空。', function(){name.focus();});
		return;
	}
	if(!isNotNull(phone.val()))
	{
  		showMsg('电话不能为空。', function(){phone.focus();});
		return;
	}else{
		var phones = phone.val().split(";");
    	for(var i=0;i<phones.length;i++){
    		//if(isNotNull(phones[i]) && !isphone.test(phones[i])){
    		if(isNotNull(phones[i]) && !(phones[i].isMobile()||phones[i].isTel())){
    			showMsg('电话格式不对。', function(){phone.focus();});
				return;
			}
    	}
	}
	
	if(isNotNull(email.val()))
	{
    	var emails = email.val().split(";");
    	for(var i=0;i<emails.length;i++){
    		if(isNotNull(emails[i]) && !isemail.test(emails[i])){
				showMsg('邮箱格式不对。', function(){email.focus();});
				return;
			}
    	}
    	
	}
	
	if(description.val().length > 100)
	{
		showMsg('描述不能超过100字。', function(){description.focus();});
		return;
	}

	var url = 'inner/common/addContact.action';
	ajaxAction(url, 'post', 'frm', true, function(result) {
		if ('success' == result) {
			window.opener.searchThis();
			window.close();
		}
	});
}

    </script>
  </body>
</html>
